<%@ page contentType="text/html;charset=UTF-8" %>
<%@ include file="/WEB-INF/views/include/taglib.jsp"%>
<html>
<head>
	<title>出库质检</title>
	<meta name="decorator" content="default"/>
	<script type="text/javascript">
		$(document).ready(function() {
			
			$("#btnButton").click(function(){
				top.$.jBox.confirm("确认不通过吗？","系统提示",function(v,h,f){
					if(v=="ok"){
						$("#inputForm").attr("action","${ctx}/ka/productManage/noPass");
						$("#inputForm").submit();
					}
				},{buttonsFocus:1});
				top.$('.jbox-body .jbox-icon').css('top','55px');
			});
			
			
			//$("#name").focus();
			$("#inputForm").validate({
				submitHandler: function(form){
					loading('正在提交，请稍等...');
					form.submit();
				},
				errorContainer: "#messageBox",
				errorPlacement: function(error, element) {
					$("#messageBox").text("输入有误，请先更正。");
					if (element.is(":checkbox")||element.is(":radio")||element.parent().is(".input-append")){
						error.appendTo(element.parent().parent());
					} else {
						error.insertAfter(element);
					}
				}
			});
		});
		
		function delRow(obj, prefix){
			var id = $(prefix+"_id");
			var delFlag = $(prefix+"_delFlag");
			if (id.val() == ""){
				$(obj).parent().parent().remove();
			}
		}
		
		function addRow(list, idx, tpl, row){
			
			$(list).append(Mustache.render(tpl, {
				idx: idx, delBtn: true, row: row
			}));
			$(list+idx).find("select").each(function(){
				$(this).val($(this).attr("data-value"));
			});
			
			$(list+idx).find("input[type='checkbox']").each(function(){
				var ss = $(this).attr("data-value");
				for (var i=0; i<ss.length; i++){
					if($(this).val() == ss[i]){
						$(this).attr("checked","checked");
					}
				}
			});
			
		}
		
		function changePrice(){
			
			var salesPrice = $("#salesPrice").val();
			var activePrice = $("#activePrice").val();
			if(parseFloat(salesPrice)>=parseFloat(activePrice)){
				$("#realPrice").val(parseFloat(salesPrice)-parseFloat(activePrice));
			}else{
				$("#activePrice").val("0.0");
				$("#realPrice").val(salesPrice);
			}
		}
	</script>
</head>
<body>
	<ul class="nav nav-tabs">
		<li class="active"><a href="${ctx}/ka/productManage/outboundInspecForm?id=${productManage.id}">售出质检</a></li>
	</ul><br/>
	<form:form id="inputForm" modelAttribute="productManage" action="${ctx}/ka/productManage/outboundInspec" method="post" class="form-horizontal">
		<form:hidden path="id"/>
		<sys:message content="${message}"/>		
		<div class="control-group">
			<label class="control-label">货号：</label>
			<div class="controls">
				<form:input path="productCode" htmlEscape="false" maxlength="64" class="input-xlarge required" readonly="true"/>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">品类：</label>
			<div class="controls">
				<form:select path="categoryId" class="input-medium required" disabled="true">
					<form:option value="" label=""/>
					<form:options items="${fns:getCategory() }" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">渠道：</label>
			<div class="controls">
				<form:select path="canalId" class="input-medium required">
					<form:options items="${fns:getCanal() }" itemLabel="label" itemValue="value" htmlEscape="false"/>
				</form:select>
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">件数：</label>
			<div class="controls">
				<form:input path="num" htmlEscape="false" maxlength="5" class="input-xlarge required digits" />件
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">入库价格：</label>
			<div class="controls">
				<form:input path="price" htmlEscape="false" maxlength="7" class="input-xlarge required" readonly="true" />元
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">出库价格：</label>
			<div class="controls">
				<form:input path="outstockPrice" value="${productManage.price}" htmlEscape="false" maxlength="7" class="input-xlarge required number" />元
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">销售价格：</label>
			<div class="controls">
				<form:input path="salesPrice" htmlEscape="false" maxlength="7" class="input-xlarge required number" onblur="changePrice()"/>元
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">活动优惠：</label>
			<div class="controls">
				<form:input path="activePrice" htmlEscape="false" maxlength="7" class="input-xlarge required number" onblur="changePrice()"/>元
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">实际销售价格：</label>
			<div class="controls">
				<form:input path="realPrice" htmlEscape="false"  value="${productManage.salesPrice}" maxlength="7" class="input-xlarge required number" readonly="true"/>元
				<span class="help-inline"><font color="red">*</font> </span>
			</div>
		</div>
		<div class="control-group">
			<label class="control-label">物料添加：</label>
			<div class="controls">
					<table id="contentTable" class="table table-striped table-bordered table-condensed">
						<thead>
							<tr>
								<th class="hide"></th>
								<th>物料明细</th>
								<th>物料数量</th>
								<th>删除</th>
							</tr>
						</thead>
						<tbody id="eventMaterialList">
						</tbody>
						<shiro:hasPermission name="ka:productManage:edit"><tfoot>
							<tr><td colspan="10"><a href="javascript:" onclick="addRow('#eventMaterialList', eventMaterialRowIdx, eventMaterialTpl);  eventMaterialRowIdx = eventMaterialRowIdx + 1;" class="btn">新增</a></td></tr>
						</tfoot></shiro:hasPermission>
					</table>
					<script type="text/template" id="eventMaterialTpl">//<!--
						<tr id="eventMaterialList{{idx}}">
							<td class="hide">
								<input id="eventMaterialList{{idx}}_id" type="hidden" value="{{row.id}}"/>
							</td>
							<td>
								<select name="eventMaterialList[{{idx}}].id" data-value="{{row.id}}">
									<option value=""></option>
									<c:forEach items="${fns:getMateria() }" var="v">
										<option value="${v.value}">${v.label}</option>
									</c:forEach>
								</select>
							</td>
							<td>
								<input id="eventMaterialList{{idx}}_amount" name="eventMaterialList[{{idx}}].amount" type="text" value="{{row.amount}}" maxlength="255" class="input-small"/>
							</td>
							<shiro:hasPermission name="ka:productManage:edit"><td class="text-center" width="10">
								{{#delBtn}}<span class="close" onclick="delRow(this, '#eventMaterialList{{idx}}')" title="删除">&times;</span>{{/delBtn}}
							</td></shiro:hasPermission>
						</tr>//-->
					</script>
					<script type="text/javascript">
						var eventMaterialRowIdx = 0, eventMaterialTpl = $("#eventMaterialTpl").html().replace(/(\/\/\<!\-\-)|(\/\/\-\->)/g,"");
						$(document).ready(function() {
							var data = ${fns:toJson(productManage.eventMaterialList)};
							for (var i=0; i<data.length; i++){
								addRow('#eventMaterialList', eventMaterialRowIdx, eventMaterialTpl, data[i]);
								eventMaterialRowIdx = eventMaterialRowIdx + 1;
							}
						});
					</script>
			</div>
		</div>
		<div class="form-actions">
			<shiro:hasPermission name="ka:productManage:edit"><input id="btnSubmit" class="btn btn-primary" type="submit" value="通过"/>&nbsp;</shiro:hasPermission>
			<shiro:hasPermission name="ka:productManage:edit"><input id="btnButton" class="btn btn-primary" type="button" value="不通过"/>&nbsp;</shiro:hasPermission>
		</div>
	</form:form>
</body>
</html>